//
//  EcontractCell.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2021/7/23.
//  Copyright © 2021 zwb. All rights reserved.
//

import UIKit

class ZyaEcontractCell: UITableViewCell {
    
    lazy var statusBtn:UIButton = {
        let v = UIButton()
        v.setImage(UIImage(named:"signsign"), for: .normal)
        return v
    }()
    lazy var bg:UIView = {
        let v = UIView()
        v.layer.masksToBounds = true
        v.layer.cornerRadius = 8
        v.backgroundColor = .white
        return v
    }()
    
    lazy var headerView:UIView = {
        let v = UIView()
        v.backgroundColor = Theme.primaryColor()
        return v
    }()
    
    
    lazy var left1: UILabel = {
        let v = UILabel()
        v.textColor = .white
        v.font = UIFont.systemFont(ofSize: 15)
        return v
    }()
    lazy var left2: UILabel = {
        let v = UILabel()
        v.font = UIFont.systemFont(ofSize: 15)
        return v
    }()
    lazy var accPeriodLab: UILabel = {
        let lab = UILabel().easy(.red, .systemFont(ofSize: 15))
            .extTextAligment(aligment: .right).extClipsToBounds(bounds: true)
        return lab
    }()
    lazy var left3: UILabel = {
        let v = UILabel()
        v.font = UIFont.systemFont(ofSize: 15)
        return v
    }()
    lazy var left4: UILabel = {
        let v = UILabel()
        v.font = UIFont.systemFont(ofSize: 15)
        return v
    }()
    lazy var left5: UILabel = {
        let v = UILabel()
        v.font = UIFont.systemFont(ofSize: 15)
        return v
    }()
    lazy var left6: UILabel = {
        let v = UILabel()
        v.font = UIFont.systemFont(ofSize: 15)
        return v
    }()
    lazy var left7: UILabel = {
        let v = UILabel()
        v.font = UIFont.systemFont(ofSize: 15)
        return v
    }()
   
    var operateBtn:OperateBtnGroup!
    // 检查整改
    var  one: ZyaESignModel? {
        didSet {
            left1.text = one!.sDjType.unwrap + "  " + one!.sNo.unwrap
            
            if let period = one!.period {
                accPeriodLab.text = "账期: \(period)天"
                if period < 7 {
                    accPeriodLab.extTextColor(color: .systemRed)
                } else if period < 30 {
                    accPeriodLab.extTextColor(color: Theme.blue)
                } else {
                    accPeriodLab.extTextColor(color: Theme.primaryColor())
                }
                
            } else {
                accPeriodLab.text = ""
            }
            accPeriodLab.sizeToFit()
            accPeriodLab.snp.updateConstraints { make in
                make.width.equalTo(accPeriodLab.ks_width + 2)
            }
            
            left2.text = "公司：" + one!.orgName.unwrap
            left3.text = "日期：" + one!.sDate.unwrap
            left4.text = "金额：" + one!.sMoney.unwrap
            left5.text = "入库比：" + one!.inLibrary.unwrap
            left6.text = "付款比：" + one!.payment.unwrap
            var sss = ""
            sss += one!.out_library == "1" ? "出库附件✔️，" : "出库附件❌，"
            sss += one!.invoice == "1" ? "发票附件✔️，" : "发票附件❌，"
            sss += one!.contract == "1" ? "合同附件✔️" : "合同附件❌"

            left7.text = sss

            
        }
    }
    
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.contentView.backgroundColor = UIColor(kshex: "#f2f2f2")
        self.contentView.addSubview(bg)
        bg.snp.makeConstraints { make in
            make.left.top.equalTo(self.contentView).offset(5)
            make.right.bottom.equalTo(self.contentView).offset(-5)
        }
        // Initialization code
        bg.addSubview(headerView)
        headerView.snp.makeConstraints { make in
            make.left.top.right.equalTo(bg)
            make.height.equalTo(35)
        }
        headerView.addSubview(left1)
        left1.snp.makeConstraints { make in
            make.left.equalTo(headerView).offset(8)
            make.centerY.equalTo(headerView)
        }
        
        bg.addSubview(statusBtn)
        statusBtn.snp.makeConstraints { make in
            make.right.equalTo(bg).offset(-8)
            make.bottom.equalTo(bg).offset(-10)
            make.width.equalTo(35)
            make.height.equalTo(33)
        }
        
        bg.addSubview(accPeriodLab)
        accPeriodLab.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-8)
            make.top.equalTo(headerView.snp.bottom).offset(5)
            make.width.equalTo(0.01)
        }
        
        bg.addSubview(left2)
        left2.snp.makeConstraints { make in
            make.left.equalTo(bg).offset(8)
            make.top.equalTo(headerView.snp.bottom).offset(5)
            make.right.equalTo(accPeriodLab.snp.left)
        }
        
        bg.addSubview(left3)
        left3.snp.makeConstraints { make in
            make.left.equalTo(bg).offset(8)
            make.top.equalTo(left2.snp.bottom).offset(5)
        }
        
        bg.addSubview(left4)
        left4.snp.makeConstraints { make in
            make.right.equalTo(bg).offset(-8)
            make.centerY.equalTo(left3)
        }
        
        bg.addSubview(left5)
        left5.snp.makeConstraints { make in
            make.left.equalTo(bg).offset(8)
            make.top.equalTo(left3.snp.bottom).offset(5)
        }
        bg.addSubview(left6)
        left6.snp.makeConstraints { make in
            make.right.equalTo(bg).offset(-8)
            make.centerY.equalTo(left5)
        }
        bg.addSubview(left7)
        left7.snp.makeConstraints { make in
            make.left.equalTo(bg).offset(8)
            make.top.equalTo(left5.snp.bottom).offset(5)
        }
        operateBtn = OperateBtnGroup(frame: CGRect.zero,btnAlignment:.right,cRadius_group: 17, titles: [],bWidth_group: 80)
        bg.addSubview(operateBtn)
        operateBtn.snp.makeConstraints { (make) in
            make.bottom.equalTo(bg).offset(-8)
            make.right.equalTo(statusBtn.snp.left).offset(-10)
            make.width.equalTo(380)
            make.height.equalTo(35)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
    
}
